﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using BankingLibrary;
using Moq;

namespace TestBankingLibrary
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void Test_AccountWithInterface_WithdrawAboveAuditTreshold()
        {
            Mock<IAuditLogger> mock = new Mock<IAuditLogger>(); 
            AccountWithInterface account = new AccountWithInterface(mock.Object);
            account.Withdraw(10001);
            mock.Verify(m => m.Log(It.IsAny<string>())); 
        }

        [TestMethod]
        public void Test_AccountWithDelegate_Instance_WithdrawAboveAuditTreshold()
        {
            Mock<IAuditLogger> mock = new Mock<IAuditLogger>();
            AccountWithDelegate account = new AccountWithDelegate();
            account.AddAuditLogger(mock.Object.Log);
            account.Withdraw(10001);
            mock.Verify(m => m.Log(It.IsAny<string>()));
        }


        [TestMethod]
        public void Test_AccountWithDelegate_localMethod_WithdrawAboveAuditTreshold()
        {
            
            AccountWithDelegate account = new AccountWithDelegate();
            account.AddAuditLogger(this.Log);
            account.AddAuditLogger(this.Log2);
            account.Withdraw(10001);
            Assert.IsTrue(logCalled);
            Assert.IsTrue(logCalled2);
        }
        private bool logCalled;

        public  void Log(string message)
        {
            logCalled=true;
        }
        private bool logCalled2;

        public void Log2(string message)
        {
            logCalled2 = true;
        }

        private bool logCalled3;

        public int Log3(string message)
        {
            logCalled3 = true;
            return 1;
        }


        [TestMethod]
        public void Test_AccountWithEvent_localMethod_WithdrawAboveAuditTreshold()
        {

            AccountWithEvent account = new AccountWithEvent();
            account.Logger += this.Log;
            account.Logger += this.Log2;
            account.Withdraw(10001);
            Assert.IsTrue(logCalled);
            Assert.IsTrue(logCalled2);
        }



        [TestMethod]
        public void Test_AccountWithFunc_localMethod_WithdrawAboveAuditTreshold()
        {

            AccountWithFunc account = new AccountWithFunc();
            account.AddAuditLogger(Log3);
            account.Withdraw(10001);
            Assert.IsTrue(logCalled3);
        
        }
    }
}
